define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'bootstrap-daterangepicker'], function ($, undefined, Backend, Table, Form, Template, daterangepicker) {

    var Controller = {
        detail: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    detail_url: 'exam/report/detail/ids/' + Fast.api.query('ids') + location.search,
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.detail_url,
                pk: 'id',
                sortName: 'total_score',
                detailView: true,
                columns: [
                    {field: 'name', title: __('名称'), formatter: Controller.api.formatter.name},
                    {field: 'sort', title: __('校级排名'),},
                    {field: 'total_score', title: __('总分'), operate: false},
                    {field: 'average_score', title: __('平均分'), operate: false},
                    {field: 'excellent_rate', title: __('优秀率'), operate: false},
                    {field: 'pass_rate', title: __('及格率'), operate: false},
                ],
                onExpandRow: function (index, row, $detail) {
                    var cur_table = $detail.html('<table></table>').find('table');
                    $(cur_table).bootstrapTable({
                        data: row.json,
                        pk: 'id',
                        sortName: 'total_score',
                        toolbar: false,
                        search: false,
                        showToggle: false,
                        showColumns: false,
                        showExport: false,
                        pagination: false,
                        columns: [
                            {field: 'name', title: __('名称'),},
                            {field: 'sort', title: __('校级排名'),},
                            {field: 'total_score', title: __('总分'), operate: false},
                            {field: 'average_score', title: __('平均分'), operate: false},
                            {field: 'excellent_rate', title: __('优秀率'), operate: false, formatter:Controller.api.formatter.rate},
                            {field: 'pass_rate', title: __('及格率'), operate: false, formatter:Controller.api.formatter.rate},
                        ],
                    });
                }
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                name: function (value, row) {
                    return row.grade_name + row.class_name;
                },
                rate: function (value, row) {
                    return value + '%';
                }
            }
        }
    };
    return Controller;
});